<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-store"/>
    <meta http-equiv="Expires" content="0"/>
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/static/favicon2.ico}">
    <link rel="stylesheet" th:href="@{/static/plugins/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/static/css/layout.css}">
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <style>
        .page-content {
            padding: 10px;
        }

        .layui-upload-img {
            width: 160px;
            height: 160px;
            /* margin: 0 10px 10px 0; */
            border: 1px solid #ddd;
            text-align: center;
            cursor: pointer;
        }
        a{
            color:cornflowerblue;
        }
        .must:after{
            content: "*";
            color: red;
        }
        a:hover{
            color:blue;
        }
    </style>
</head>
<body>
<div class="page-content">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label must">机构名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" readonly th:disabled="${session.organization.name != null}" th:value="${session.organization.name}" autocomplete="off" th:class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label must">联系人</label>
            <div class="layui-input-block">
                <input type="text" name="contactPerson"  lay-verify="required" placeholder="请输入联系人"
                       autocomplete="off"
                       class="layui-input" maxlength="10">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label must">联系电话</label>
            <div class="layui-input-block">
                <input type="text" name="contactPersonPhone"  lay-verify="phone|required|number" placeholder="请输入联系人电话"
                       autocomplete="off"
                       class="layui-input" maxlength="11">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label must">民政部门</label>
            <div class="layui-input-block">
                <input type="text" name="mzName" readonly="readonly" th:value="${org.mzName}" autocomplete="off" class="layui-input">
                <input type="hidden" name="mzCode" readonly="readonly" th:value="${org.mzCode}" autocomplete="off" class="layui-input">
            </div>
        </div>


      <!-- 上传养老机构备案申请书-->
        <div class="layui-row">
            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label must" style="padding-top: 95px;">备案申请书</label>
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <div class="layui-upload-list">
                                <img class="layui-upload-img file1" src="/static/imgs/imgup.png">
                                <input type="hidden" name="applicationFormPath" class="hiddenIpt1"  lay-verify="required">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-col-sm4">
                <div class="layui-form-item">
                    <label class="layui-form-label must" style="padding-top: 95px;">备案承诺书</label>
                    <div class="layui-input-block">
                        <div class="layui-upload-list">
                            <img class="layui-upload-img file2" src="/static/imgs/imgup.png">
                            <input type="hidden" name="letterOfCommitment" class="hiddenIpt2"  lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm4">
                <p style="margin-top: 20px">
                    <a href="/storage/files/dl/养老机构基本条件告知书.docx" lay-event="download">《养老机构基本条件告知书》</a>
                </p>
                <p style="margin-top: 20px">
                    <a href="/storage/files/dl/养老机构备案申请书.docx"  lay-event="download">《养老机构备案申请书》</a>
                </p>
                <p style="margin-top: 20px">
                    <a href="/storage/files/dl/备案承诺书.docx"  lay-event="download">《养老机构备案承诺书》</a>
                </p>

            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-sm5">
                <div class="layui-form-item">
                    <div class="layui-input-block">

                    </div>
                </div>
            </div>
            <div class="layui-col-sm5">
                <div class="layui-form-item">
                    <div class="layui-input-block">

                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formsb">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

</div>
<script th:src="@{/static/plugins/jquery.js}"></script>
<script th:src="@{/static/plugins/layui/layui.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:src="@{/static/plugins/jquery-migrate-1.2.1.min.js}"></script>
<script th:src="@{/static/plugins/jquery.jqprint-0.3.js}"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['element', 'form', 'upload'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , upload = layui.upload,
            form = layui.form;

        upload.render({
            elem: '.file1'
            ,url: '/storage/files/ul'
            ,field: 'file'
            ,accept:"images"
            ,acceptMime:"image/jpg,image/jpeg,image/png"
            ,size:5120
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                var that = this;
                obj.preview(function(index, file, result){
                    $(that.elem).attr('src', result); //图片链接（base64）
                });
            }
            ,done: function (res) {
                //如果上传失败
                if (res.code !== 200) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var $target = $(this.elem);
                $target.parent().find(".hiddenIpt1").val(res.data.path);
            }
            ,
            error: function () {
                //演示失败状态
                var $target = $(this.elem);
                var demoText = $target.parent().find(".msg-box")
                demoText.html('<span style="color: #FF5722;">上传失败!</span>');
            }
        });
        upload.render({
            elem: '.file2'
            ,url: '/storage/files/ul'
            ,field: 'file'
            ,accept:"images"
            ,acceptMime:"image/jpg,image/jpeg,image/png"
            ,size:5120
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                var that = this;
                obj.preview(function(index, file, result){
                    $(that.elem).attr('src', result); //图片链接（base64）
                });
            }
            ,done: function (res) {
                //如果上传失败
                if (res.code !== 200) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var $target = $(this.elem);
                $target.parent().find(".hiddenIpt2").val(res.data.path);
            }
            ,
            error: function () {
                //演示失败状态
                var $target = $(this.elem);
                var demoText = $target.parent().find(".msg-box")
                demoText.html('<span style="color: #FF5722;">上传失败!</span>');
            }
        });


        form.on('submit(formsb)', function (data) {
            console.log();
            $.ajax({
                url: '/filing/filingSubmitted',
                data: data.field,
                type: 'post',
                dataType: 'json',
                async: false,
                success: function (rs) {
                    if (rs.code === 200) {
                        location.reload();
                        parent.layer.msg(rs.message);
                        parent.layer.close(parent.oo);
                        parent.location.reload();
                    } else {
                        layer.msg(rs.message);
                    }
                }
            });

            return false;
        });


    });
</script>
</body>

</html>